﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.Common;
using System.Data;
using RegisterationCommon.Student;

namespace RegisterationSystem.Space_Education
{
    public partial class sys_set : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Form["action"] != "")
                {
                    switch (Request.Form["action"])
                    {
                        case "InitSet":
                            InitSet();
                            break;
                        case "SetSystem":
                            SetSystem();
                            break;
                    }
                }
            }
        }

        /// <summary>
        /// 初始化设置信息
        /// </summary>
        public void InitSet()
        {
            DataTable dt = DBAction.GetDTFromSQL("select * from Sys_Set");
            bool isStop = false;
            string res = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            if (dt.Rows.Count > 0)
            {
                if ((bool)dt.Rows[0]["IsStopSignUp"])
                {
                    isStop = true;
                }
                if (!string.IsNullOrEmpty(dt.Rows[0]["StopSignUpDateTime"].ToString()))
                {
                    res = dt.Rows[0]["StopSignUpDateTime"].ToString();
                }
            }
            Response.Clear();
            Response.Write(isStop + "|" + res);
            Response.End();
        }

        /// <summary>
        /// 提交设置信息
        /// </summary>
        public void SetSystem()
        {
            bool isStop = Convert.ToBoolean(Request.Form["IsStop"].ToString().Trim());
            DateTime stopTime = Convert.ToDateTime(Request.Form["StopTime"].ToString().Trim());
            RParams param = new RParams ();
            param.Add("IsStopSignUp",isStop);
            param.Add("StopSignUpDateTime",stopTime);
            DBAction.Update("Sys_Set","IsStopSignUp,StopSignUpDateTime","Id>0",param);
            Response.Clear();
            Response.Write("ok");
            Response.End(); 
        }
    }
}